import { reqUserLogin } from '@/api/user'

export default {
  // vue3里是一个函数返回数据
  namespaced: true,
  state: () => {
    return {
      profile: {
        id: '',
        token: '',
        nickname: '',
        avatar: '',
        mobile: ''
      }
    }
  },
  mutations: {
    setProfile (state, newProfile) {
      state.profile = newProfile
    },
    // 清空state数据
    clearProfile (state) {
      state.profile = {
        id: '',
        token: '',
        nickname: '',
        avatar: '',
        mobile: ''
      }
    }
  },
  actions: {
    async login (context, data) {
      const res = await reqUserLogin(data)
      // console.log('res', res)
      context.commit('setProfile', res.result)
    }
  }
}
